#input date beaglefile markerlist to restrict filetring
$input_marker = $ARGV[0];
chomp($input_marker);
open(INP,$input_marker) or die "no input marker file exists\n";

#opening the maf markers and stroing int he hash
$bim_file_maf = $ARGV[1];
chomp($bim_file_maf);
open(BUFF,$bim_file_maf) or die "no maf marker file exists\n";

#dosage file
$dosagefile = $ARGV[2];
chomp($dosagefile);
open(DOS,$dosagefile) or die " no dosage file exists $dosagefile\n";

#new dosage file
$newdosagefile = $ARGV[3];
chomp($newdosagefile);
open(NDOS,">$newdosagefile") or die " no new dosage file exists $newdosagefile\n";

#reading input markers
$line = <INP>;
#print $line."\n";
$line = <INP>;
while(<INP>)
{
        chomp($_);
        @a = split(/ /,$_);
        $inp{$a[1]} =1;
	#print "$a[1]\n";	
}
close(INP);
@a =();
#reading maf markers 1000 genome
while(<BUFF>)
{
	chomp($_);
	@a = split(/\t/,$_);
	$hash{$a[1]} =1;
	#print "$a[1]\n";
}
close(BUFF);
@a =();
#filetering the dosage file
$line =<DOS>;
print NDOS $line;
while(<DOS>)
{
	chomp($_);
	@a = split(" ",$_);
	if(exists($inp{$a[0]}) || exists($hash{$a[0]}))
	{
		print NDOS $_."\n";
	}
}
close(DOS);
close(NDOS);
